package com.candy.test;

import com.candy.dao.AccountDao;
import com.candy.dao.impl.AccountDaoImpl;
import com.candy.model.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Client {
    public static void main(String[] args) {
        //1.使用 ApplicationContext 接口，就是在获取 spring 容器
//        ApplicationContext ac=  new FileSystemXmlApplicationContext("C:\\Users\\Administrator\\Desktop\\beans.xml");
        ClassPathXmlApplicationContext ac= new  ClassPathXmlApplicationContext("spring-beans.xml");
//        ClassPathXmlApplicationContext ac= new  ClassPathXmlApplicationContext("beans.xml");
        //2.根据 bean 的 id 获取对象
        AccountDao accountDao= ac.getBean("accountDao", AccountDaoImpl.class);
        AccountDao accountDao2= ac.getBean("accountDao", AccountDaoImpl.class);
        System.out.println(accountDao==accountDao2);
//        关闭容器，单例模式下对象销毁
        ac.close();

    }
    public static void test02() {
        //1.使用 ApplicationContext 接口，就是在获取 spring 容器
//        ApplicationContext ac=  new FileSystemXmlApplicationContext("C:\\Users\\Administrator\\Desktop\\beans.xml");
        ApplicationContext ac= new  ClassPathXmlApplicationContext("spring-beans.xml");
//        ClassPathXmlApplicationContext ac= new  ClassPathXmlApplicationContext("beans.xml");

        //2.根据 bean 的 id 获取对象
        AccountService accountService=(AccountService)ac.getBean("accountService");
        System.out.println(accountService);
        accountService.save();



//        关闭容器，单例模式下对象销毁
//        ac.close();
    }
    public static void test() {
        //1.使用 ApplicationContext 接口，就是在获取 spring 容器
//        ApplicationContext ac=  new FileSystemXmlApplicationContext("C:\\Users\\Administrator\\Desktop\\beans.xml");
        ApplicationContext ac= new  ClassPathXmlApplicationContext("beans.xml");
//        ClassPathXmlApplicationContext ac= new  ClassPathXmlApplicationContext("beans.xml");

        //2.根据 bean 的 id 获取对象
        AccountService accountService=(AccountService)ac.getBean("accountService");
        System.out.println(accountService);

       AccountDao accountDao= ac.getBean("accountDao", AccountDaoImpl.class);
        System.out.println(accountDao);
//        关闭容器，单例模式下对象销毁
//        ac.close();

    }
}
